#include "SpriteFps.h"



Sprite::SpriteFps::~SpriteFps( void )
{
	Delete(m_pCFont);
}

Sprite::SpriteFps::SpriteFps( void )
{
	m_pCFont = NULL;
	m_pCMainTimer = NULL;
}

Sprite::SpriteFps::SpriteFps( SpriteTimer* timer ):m_pCMainTimer(timer)
{
	m_pCFont = NULL;
}

void Sprite::SpriteFps::update( float dt )
{
	static int frameCnt = 0;
	static float t_base = 0.0f;
	frameCnt++;
	// Compute averages over one second period.
	if( (m_pCMainTimer->getGameTime() - t_base) >= 1.0f )
	{
		float fps = (float)frameCnt; // fps = frameCnt / 1
		float mspf = 1000.0f / fps;

		std::wostringstream outs;   
		outs.precision(6);
		outs << L"FPS: " << fps << L"\n" 
			<< "Milliseconds: Per Frame: " << mspf;
		mFrameStats = outs.str();
		// Reset for next average.
		frameCnt = 0;
		t_base  += 1.0f;
	}		
}

HRESULT Sprite::SpriteFps::init()
{
	m_pCFont = new SpriteFont();
	return S_OK;
}

void Sprite::SpriteFps::draw( void )
{
	m_pCFont->draw(this->mFrameStats);
}

